package com.mingshashan.building.easy.core.service.impl;

import com.mingshashan.building.easy.core.common.IMybatisConstants;
import com.mingshashan.building.easy.core.dao.ITestMapper;
import com.mingshashan.building.easy.core.entity.Test;
import com.mingshashan.building.easy.core.service.ITestService;
import com.mingshashan.building.easy.core.vo.TestVO;
import com.mingshashan.building.easy.id.generator.IdGenerator;
import com.mingshashan.building.easy.log.Logger;
import com.mingshashan.building.easy.log.LoggerFactory;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * TestServiceImpl
 *
 * @author jasonxu
 */
@Service
public class TestServiceImpl implements ITestService {

    private static final Logger logger = LoggerFactory.getLogger(TestServiceImpl.class);

    @Autowired
    private ITestMapper testMapper;

    @Autowired
    private ModelMapper modelMapper;

    @Autowired
    private IdGenerator idGenerator;

    @Override
    public TestVO addTest(TestVO testVO) {

        logger.error("HAHA");
        Test test = modelMapper.map(testVO, Test.class);

//        Test savedVO = testMapper.insert(test);

        test.setId(idGenerator.nextId());
        int result = testMapper.insert(test);

        if (IMybatisConstants.INSERT_RESULT != result) {
            logger.error("add test error");
        }

        return modelMapper.map(test, TestVO.class);
    }

    @Override
    public String hello() {
        return "Hello";
    }
}
